package com.hdu.hot100.matricx;

public class lc48 {
    class Solution {
        public void rotate(int[][] matrix)
        {
            int a = 0;
            int b = 0;
            int c = matrix.length - 1;
            int d = matrix.length - 1;
            while (a < c)
            {
                handle(matrix, a, b, c, d);
                a++;
                b++;
                c--;
                d--;
            }
        }

        void handle(int[][] matrix, int a, int b, int c, int d)
        {
            int swapTimes = d - b;
            for (int i = 0; i < swapTimes; i++)
            {
                int tmp = matrix[a][b + i];
                matrix[a][b + i] = matrix[c - i][b];
                matrix[c - i][b] = matrix[c][d - i];
                matrix[c][d - i] = matrix[a + i][d];
                matrix[a + i][d] = tmp;
            }
        }
    }
}
